<?php
define("SERVER_MEMCACHED_HOST","127.0.0.1");
define("SERVER_MEMCACHED_PORT","11211");

define("SERVER_TT_HOST","127.0.0.1");
define("SERVER_TT_PORT","11211");

function init_domain($server_name){
    //if(function_exists("memcache_connect")){
        $memcache_obj = @memcache_connect(SERVER_MEMCACHED_HOST, SERVER_MEMCACHED_PORT);
        $tt_obj = @memcache_connect(SERVER_TT_HOST, SERVER_TT_PORT);
    //}else{
    //    $memcache_obj = false;
    //    $tt_obj = false;
    //}
    if( $memcache_obj && $data = memcache_get($memcache_obj,$server_name)){
        $data = unserialize($data);
    }else{
        if( $tt_obj && $data = memcache_get($tt_obj,$server_name)){
            if($memcache_obj)
                $memcache_obj->set($server_name, $data);
            $data = unserialize($data);
        }else{
            @include "user_deploy.php";
            if($data = $deploy_data[$server_name]){
                if($memcache_obj)
                    $memcache_obj->set($server_name, serialize($data));
                if($tt_obj)
                    $tt_obj->set($server_name, serialize($data));
            }else{
                echo '<h2>No record for: '.$_SERVER['SERVER_NAME'].'</h2>';
                exit(1);
            }
        }
    }
    foreach($data as $k=>$v){
       define($k,$v);
    }
}
init_domain($_SERVER['SERVER_NAME']);

define('LOG_TYPE', 0);

define('FILE_STORAGER','ttsystem');
define('STORAGE_MEMCACHED','192.168.2.119:16001');
//define('HOST_MIRRORS','http://pic1.com:20133');
define('STORAGE_HOST','http://pic2.com:20133');

define('KVSTORE_STORAGE', 'base_kvstore_tokyotyrant');
define('KVSTORE_MEMCACHE_CONFIG', '192.168.2.119:11211');

define('CACHE_STORAGE', 'base_cache_memcache');
define('CACHE_MEMCACHE_CONFIG', '192.168.2.119:11211');

//如果TT信息中不存在KV_PREFIX则定义为域名的md5
if(!defined("KV_PREFIX")){
    define('KV_PREFIX', md5($_SERVER['SERVER_NAME']));
}


function set_certificate($certificate){
    base_kvstore::instance('certificate')->store('cert', $certificate);
}

function get_certificate(){
    if(base_kvstore::instance('certificate')->fetch('cert', $certificate)){
        return $certificate;
    }
}